package thread.atomic;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerTest extends Thread {

    String name = "";
    public  AtomicIntegerTest(String name){
        super(name);
    }
    public static void main(String[] args) throws InterruptedException {
        AtomicIntegerTest atomicIntegerTest = new AtomicIntegerTest("线程1");
        AtomicIntegerTest atomicIntegerTest1 = new AtomicIntegerTest("线程2");
        atomicIntegerTest.start();
        atomicIntegerTest1.start();
        atomicIntegerTest.join();
        atomicIntegerTest1.join();
        //System.out.println(a);
        System.out.println(atomicInteger.get());
    }

    ///static int a = 0;
    static AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public void run() {
        for (int i = 0;i<10000;i++){
            atomicInteger.incrementAndGet();
            System.out.println(Thread.currentThread().getName()+"操作");
            //a++;
        }
    }
}
